<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>testJSON</title>
</head>
<body>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
<script>
    <!--Json对象-->
    var user = {
        "username": "hahah",
        "password": "123456"
    };

    // 前端传递数据不用转换为Json字符串：Json.stringify(user)
    $.ajax({
        url:"/testJson",
        type: "GET",
        async: true,
        data: user,//Json对象
        dataType: 'json',
        success: function (data) {
        }
    });
</script>

<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>

<script>
    var user = {
        "username": "hahah",
        "password": "123456"
    };

    $.ajax({
        url:"/testJson3",
        type: "POST",
        async: true,
        contentType: "application/json;charset=UTF-8", //使用 application/json;charset=UTF-8
        data: JSON.stringify(user), //将JSON对象转换为JSON字符串
        dataType: 'json',
        success: function (data) {

        }
    });

    $.ajax({
        url:"/testJson4",
        type: "POST",
        async: true,
        contentType: "application/json;charset=UTF-8", //使用 application/json;charset=UTF-8
        data: JSON.stringify(user), //将JSON对象转换为JSON字符串
        dataType: 'json',
        success: function (data) {

        }
    });

    $.ajax({
        url:"/testJson5",
        type: "POST",
        async: true,
        contentType: "application/json;charset=UTF-8", //使用 application/json;charset=UTF-8
        data: JSON.stringify(user), //将JSON对象转换为JSON字符串
        dataType: 'json',
        success: function (data) {

        }
    });
</script>


</body>
</html>